package net.qingchuan.sharing.algorithm;

import com.google.common.collect.Range;
import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;

import java.util.Arrays;
import java.util.Collection;

public class TabStandardRangeShardingAlgorithm implements RangeShardingAlgorithm<Long> {

    public TabStandardRangeShardingAlgorithm() {
    }

    @Override
    public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Long> rangeShardingValue) {
        System.out.println("有效表信息：" + collection);
        System.out.println("分片参数信息：" + rangeShardingValue);
        Range<Long> valueRange = rangeShardingValue.getValueRange();
        Long smallVal = valueRange.lowerEndpoint();
        Long bigVal = valueRange.upperEndpoint();
        if (bigVal < 564183025835835392L) {
            return Arrays.asList("course_1");
        } else if (smallVal > 564183025835835392L) {
            return Arrays.asList("course_2");
        } else {
            return Arrays.asList("course_1", "course_2");
        }
    }
}